package utils

/**
 * User: zhu.tan@gmail.com
 * Date: 21-Aug-2009
 */

object FileMatcher {
  private def filesMatching(dir: String, matcher: String => Boolean) = {
    val files = (new java.io.File(dir)).listFiles
    for (file <- files; if matcher(file.getName)) yield file
  }

  def filesEnding(dir: String, query: String) = filesMatching(dir, _.endsWith(query))

  def filesContaining(dir: String, query: String) = filesMatching(dir, _.contains(query))

  def filesRegex(dir: String, query: String) = filesMatching(dir, _.matches(query))


  def filesEnding(query: String) = filesMatching(".", _.endsWith(query))

  def filesContaining(query: String) = filesMatching(".", _.contains(query))

  def filesRegex(query: String) = filesMatching(".", _.matches(query))

}